package com.ruoyi.asset.cleaning.controller;


import cn.dev33.satoken.annotation.SaIgnore;
import com.ruoyi.asset.cleaning.domain.bo.*;
import com.ruoyi.asset.cleaning.domain.vo.SweepCleaningVo;
import com.ruoyi.asset.cleaning.service.ISweepCleaningService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 清扫保洁
 *
 * @author 12276
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/asset/cleaning")
public class SweepCleaningController extends BaseController {

    private final ISweepCleaningService cleaningService;

    /**
     * 获取清扫保洁-管理范围导入模板
     */
    @SaIgnore()
    @Log(title = "清扫保洁管理范围导入", businessType = BusinessType.IMPORT)
    @RepeatSubmit()
    @PostMapping(value = "/importData")
    public R<List<String>> importData(@RequestParam(name = "excelUrl") String excelUrl) {
        List<String> list = this.cleaningService.importExcel(excelUrl);

        if (list == null) {
            return R.fail();
        } else {
            return R.ok(list);
        }
    }

    /**
     * 获取清扫保洁-管理范围导入模板
     */
    @SaIgnore()
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) {
        ExcelUtil.exportExcel(new ArrayList<>(), "清扫保洁管理范围导入模板", SweepCleaningVo.class, response);
    }

    /**
     * 删除清扫保洁范围
     */
    @SaIgnore()
    @DeleteMapping("/deleteCleaning/{ids}")
    public R<Void> deleteCleaning(@NotEmpty(message = "主键不能为空")
                                          @PathVariable Set<Long> ids) {
        int count = this.cleaningService.deleteCleaning(ids);

        return toAjax(count >= 0 ? 1 : count);
    }

    /**
     * 查询路清扫保洁范围
     */
    @SaIgnore()
    @GetMapping("/queryCleaning")
    public TableDataInfo<SweepCleaningVo> queryCleaning(SweepCleaningBo searchBo, PageQuery pageQuery) {
        return this.cleaningService.queryCleaning(searchBo, pageQuery);
    }

    /**
     * 导出清扫保洁范围
     */
    @SaIgnore()
    @Log(title = "清扫保洁范围导出", businessType = BusinessType.EXPORT)
    @PostMapping("/exportCleaning")
    public void exportCleaning(SweepCleaningBo searchBo, HttpServletResponse response) {
        List<SweepCleaningVo> list = this.cleaningService.exportCleaning(searchBo);

        ExcelUtil.exportExcel(list, "清扫保洁范围", SweepCleaningVo.class, response);
    }

    @SaIgnore()
    @GetMapping("/cleaningCount")
    public R<SweepCleaningStatisticsBo> cleaningCount() {
        SweepCleaningStatisticsBo cleaningCount = cleaningService.getCleaningCount();
        return R.ok(cleaningCount);
    }

    @SaIgnore()
    @GetMapping("/cleaningCommunityCount")
    public R<Map> cleaningCommunityCount() {
        Map map = cleaningService.getCleaningCommunity();
        return R.ok(map);
    }

    @SaIgnore()
    @GetMapping("/cleaningByCommunityCount")
    public R<List<CleaningCommunityBo>> cleaningByCommunityCount() {
        List<CleaningCommunityBo> cleaningByCommunity = cleaningService.getCleaningByCommunity();
        return R.ok(cleaningByCommunity);
    }

    /**
     * 查询智慧大屏清扫保洁玉塘街道全社区
     * @param date
     * @return
     */
    @SaIgnore()
    @GetMapping("/cleaningCommunity")
    public R<List<CleaningCommunityCountBo>> cleaningCommunity(String date) {
        date = "2024-03-13";
        List<CleaningCommunityCountBo> cleaningCountByCommunity = cleaningService.getCleaningCountByCommunity(date);
        return R.ok(cleaningCountByCommunity);
    }

    /**
     * 查询智慧大屏清扫保洁今日作业统计与百分比
     * @param date 日期
     * @return
     */
    @SaIgnore()
    @GetMapping("/cleaningWorkByDate")
    public R<CleaningWorkStatisticsBo> cleaningWorkByDate(String date) {
        date = "2024-03-13";
        CleaningWorkStatisticsBo cleaningWorkByDate = cleaningService.getCleaningWorkByDate(date);
        return R.ok(cleaningWorkByDate);
    }

    /**
     * 查询智慧大屏清扫保洁今日作业统计与百分比
     * @param date 日期
     * @param community 社区名称
     * @return
     */
    @SaIgnore()
    @GetMapping("/cleaningWorkByDateAndCommunity")
    public R<CleaningWorkStatisticsBo> cleaningWorkByDateAndCommunity(String date,String community) {
        date = "2024-03-13";
        CleaningWorkStatisticsBo cleaningWorkByDate = cleaningService.getCleaningWorkByDateAndCommunity(date,community);
        return R.ok(cleaningWorkByDate);
    }

    /**
     * 查询智慧大屏清扫保洁按社区区分
     * @param community
     * @return
     */
    @SaIgnore()
    @GetMapping("/communityByDate")
    public R<CleaningCommunityMapBo> communityByDate(String community) {
        CleaningCommunityMapBo communityByDate = cleaningService.getCommunityByDate(community);
        return R.ok(communityByDate);
    }
}
